package com.zhisheng.controller;

import com.zhisheng.dto.EmpDto;
import com.zhisheng.pojo.Emp;
import com.zhisheng.pojo.MyResponseResult;
import com.zhisheng.pojo.PageBean;
import com.zhisheng.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

/**
 * 员工管理Controller
 */
@RestController
@RequestMapping("emps")
public class EmpController {

    @Autowired
    private EmpService empService;

   /* @GetMapping // 目前只有分页,没有带条件
    public MyResponseResult<PageBean<Emp>> getByPage(EmpDto dto){
        // 参  调  响
        PageBean<Emp> pageBean = empService.getByPage(dto.getPage(), dto.getPageSize(),new EmpDto());
        return MyResponseResult.ok(pageBean);
    }*/

    @GetMapping // 目前只有分页,没有带条件
    public MyResponseResult<PageBean<Emp>> getByPage(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer pageSize,  EmpDto dto){
        // 参  调  响
        PageBean<Emp> pageBean = empService.getByPage(page,pageSize,new EmpDto());

        return MyResponseResult.ok(pageBean);
    }


    @DeleteMapping("/{ids}") // 目前只有分页,没有带条件
    public MyResponseResult<Object> delByIds(@PathVariable Integer[] ids){
        // 参  调  响
        int i = empService.delByIds(ids);
        return i>=1?MyResponseResult.ok(null):MyResponseResult.error(Arrays.toString(ids)+"删除失败!");
    }


    @PostMapping
    public MyResponseResult<Object> insertEmp(@RequestBody Emp emp){
        // 参  调  响
        int i = empService.insertEmp(emp);
        return i>=1?MyResponseResult.ok(null):MyResponseResult.error("保存失败!");
    }


}
